<?php

namespace App\Admin\Controllers;

use App\Models\City;
use App\Models\Config;
use App\Models\Member\Member;
use App\Models\Nation;
use App\Models\Obj;
use App\Models\Org;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use Encore\Admin\Grid\Displayers\Actions;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use Illuminate\Support\MessageBag;
use SimpleSoftwareIO\QrCode\Facades\QrCode;


class ConfigController extends AdminController
{
    protected $title = '监测数据管理';

    protected function grid()
    {
        $grid = new Grid(new Config());

        $grid->fine_rate('优良率(%)');
        $grid->air_quality('空气质量')->using(['1' => '优', '2' => '良', '3' => '轻度污染', '4' => '中度污染', '5' => '重度污染', '6' => '严重污染'], '未知');;
        $grid->primary_pollutants('首要污染物')->using(['1' => '二氧化硫', '2' => '一氧化碳 ', '3' => '二氧化氮', '4' => '可吸入颗粒物', '5' => '臭氧'], '未知');
        $grid->column('soil_quality', '土壤质量')->using(['1' => '优', '2' => '良', '3' => '中', '4' => '差'], '未知');
        $grid->column('water_type', '水质类别')->using(['1' => 'Ⅰ类', '2' => 'ⅠⅠ类', '3' => 'ⅠⅠⅠ类', '4' => 'Ⅳ类', '5' => 'Ⅴ类'], '未知');



        $grid->disableExport();
        $grid->disableRowSelector();
        $grid->disableCreateButton();
        $grid->disablePagination();
        $grid->disableFilter();
        $grid->disableExport();
        $grid->disableRowSelector();
        $grid->disableColumnSelector();
        $grid->actions(function ($actions) {
            // 去掉删除
            $actions->disableDelete();
        });

        $grid->setActionClass(Actions::class);

        return $grid;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Config());

        $form->rate('fine_rate', '优良率')->rules('required');
        //空气质量 1优 2良 3轻度污染 4中度污染 5重度污染 6严重污染
        $form->select('air_quality', '空气质量')->options(['1' => '优', '2' => '良', '3' => '轻度污染', '4' => '中度污染', '5' => '重度污染', '6' => '严重污染'])->default('1');
        $form->select('primary_pollutants', '首要污染物')->options(['1' => '二氧化硫', '2' => '一氧化碳 ', '3' => '二氧化氮', '4' => '可吸入颗粒物', '5' => '臭氧'])->default('1');
        //首要污染物 1二氧化硫 2一氧化碳 3二氧化氮 4可吸入颗粒物 5臭氧
        $form->select('soil_quality', '土壤质量')->options(['1' => '优', '2' => '良', '3' => '中', '4' => '差'])->default('1')->default('1');  //1优 2良 3中 4差
        $form->select('water_type', '水质类别')->options(['1' => 'Ⅰ类', '2' => 'ⅠⅠ类', '3' => 'ⅠⅠⅠ类', '4' => 'Ⅳ类', '5' => 'Ⅴ类'])->default('1');


        $form->tools(function (Form\Tools $tools) {
            // 去掉`列表`按钮
            $tools->disableList();
            // 去掉`删除`按钮
            $tools->disableDelete();
            // 去掉`查看`按钮
            $tools->disableView();
        });
        $form->footer(function ($footer) {
            // 去掉`重置`按钮
            $footer->disableReset();
            // 去掉`查看`checkbox
            $footer->disableViewCheck();
            // 去掉`继续编辑`checkbox
            $footer->disableEditingCheck();
            // 去掉`继续创建`checkbox
            $footer->disableCreatingCheck();

        });

        $form->saved(function (Form $form) {

            admin_toastr('更新成功！', 'success');

            return back();

        });

        // 抛出成功信息
//        $form->saving(function ($form) {
//
//            $success = new MessageBag([
//                'title'   => '监测数据',
//                'message' => '您的数据保存成功~',
//            ]);
//
//            return back()->with(compact('success'));
//        });

        return $form;
    }
}
